package service

import (
	"context"
	"fmt"
	__ "user-srv/basic/proto"
	"user-srv/handler/dao"
)

// 添加勋章规则
func (s *Server) BadgeRulesAdd(_ context.Context, in *__.BadgeRulesAddReq) (*__.BadgeRulesAddResp, error) {

	if in.Name == "" || in.Desc == "" || in.Condition == "" {
		return nil, fmt.Errorf("参数不能为空")
	}

	add, err := dao.BadgeRulesAdd(in)
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}

	return &__.BadgeRulesAddResp{
		Id: add.Id,
	}, nil
}

// 勋章规则详情
func (s *Server) BadgeRulesDetail(_ context.Context, in *__.BadgeRulesDetailReq) (*__.BadgeRulesDetailResp, error) {
	if in.Id == 0 {
		return nil, fmt.Errorf("参数不能为空")
	}

	detail, err := dao.BadgeRulesDetail(in)
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}

	return &__.BadgeRulesDetailResp{
		Id:        detail.Id,
		Name:      detail.Name,      //勋章名称
		Desc:      detail.Desc,      //规则描述
		Condition: detail.Condition, //获取条件
	}, nil
}
